<html>
<head><meta charset="utf-8"><title>Excessive CPU Feature Requirements in the docs? · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Excessive.20CPU.20Feature.20Requirements.20in.20the.20docs.3F.html">Excessive CPU Feature Requirements in the docs?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="197104974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Excessive%20CPU%20Feature%20Requirements%20in%20the%20docs%3F/near/197104974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Excessive.20CPU.20Feature.20Requirements.20in.20the.20docs.3F.html#197104974">(May 11 2020 at 06:35)</a>:</h4>
<p>In the <code>core::arch</code> modules for x86 and x86_64 some of the avx instructions are listed as also requiring sse or sse2, as follows:</p>
<ul>
<li>avx,sse. _mm_cmp_ps</li>
<li>avx,sse. _mm_cmp_ss</li>
<li>avx,sse. _mm_permute_ps</li>
<li>avx,sse. _mm256_loadu2_m128</li>
<li>avx,sse. _mm256_storeu2_m128</li>
<li>avx,sse. _mm256_zextps128_ps256</li>
<li>avx,sse2. _mm_cmp_pd</li>
<li>avx,sse2. _mm_cmp_sd</li>
<li>avx,sse2. _mm_permute_pd</li>
<li>avx,sse2. _mm256_loadu2_m128d</li>
<li>avx,sse2. _mm256_loadu2_m128i</li>
<li>avx,sse2. _mm256_storeu2_m128d</li>
<li>avx,sse2. _mm256_storeu2_m128i</li>
<li>avx,sse2. _mm256_zextpd128_pd256</li>
<li>avx,sse2. _mm256_zextsi128_si256</li>
</ul>
<p>Given that no <em>other</em> avx instructions are listed as being avx + some sse level this seems rather out of place. I think that one of the following is most likely:</p>
<ul>
<li>The docs are wrong for these, and it shouldn't list <code>sse</code> or <code>sse2</code> as being required.</li>
<li>The docs are wrong for <em>all other</em> functions, and all other functions should also list <code>sse</code> or whatever else as part of the requirements.</li>
<li>These functions are truly extra special in some way, and they're the only intrinsics out of all the hundreds of intrinsics that really do need to have both CPU features set.</li>
</ul>
<p>And yes, I know that it would be deeply unlikely to have avx enabled without also having both sse and sse2 enabled. However, I would still like the clarification and if it's the first case we could perhaps fix the listings.</p>



<a name="197109695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Excessive%20CPU%20Feature%20Requirements%20in%20the%20docs%3F/near/197109695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Excessive.20CPU.20Feature.20Requirements.20in.20the.20docs.3F.html#197109695">(May 11 2020 at 07:35)</a>:</h4>
<p><code>avx</code> implies <code>sse2</code>, which in turn implies <code>sse</code>. It is impossible to have the <code>avx</code> feature enabled without the <code>sse</code> feature.</p>



<a name="197109747"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Excessive%20CPU%20Feature%20Requirements%20in%20the%20docs%3F/near/197109747" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Excessive.20CPU.20Feature.20Requirements.20in.20the.20docs.3F.html#197109747">(May 11 2020 at 07:36)</a>:</h4>
<p>So I guess that rules out option 3.</p>



<a name="197110188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Excessive%20CPU%20Feature%20Requirements%20in%20the%20docs%3F/near/197110188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Excessive.20CPU.20Feature.20Requirements.20in.20the.20docs.3F.html#197110188">(May 11 2020 at 07:40)</a>:</h4>
<p>Hmm those functions are marked as <code>#[target_feature(enable = "avx,sse")]</code> and a git blame shows that this dates back to the original version of the AVX intrinsics.</p>



<a name="197110208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Excessive%20CPU%20Feature%20Requirements%20in%20the%20docs%3F/near/197110208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Excessive.20CPU.20Feature.20Requirements.20in.20the.20docs.3F.html#197110208">(May 11 2020 at 07:40)</a>:</h4>
<p>I think it's safe to just change those to <code>#[target_feature(enable = "avx")]</code>.</p>



<a name="197111888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Excessive%20CPU%20Feature%20Requirements%20in%20the%20docs%3F/near/197111888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Excessive.20CPU.20Feature.20Requirements.20in.20the.20docs.3F.html#197111888">(May 11 2020 at 07:58)</a>:</h4>
<p>I seem to recall that past discussions of <code>target_feature</code> were dominated by "we don't (yet) want to get into the business of defining implications/hierarchies between different features", so I guess that's why? In a cursory search I can't find evidence that this position has changed, but maybe LLVM's own implications between target features kick in (<code>rustc --print cfg -Ctarget-feature=+avx</code> indeed lists SSE up to 4.1 as enabled)</p>



<a name="197112120"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Excessive%20CPU%20Feature%20Requirements%20in%20the%20docs%3F/near/197112120" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Excessive.20CPU.20Feature.20Requirements.20in.20the.20docs.3F.html#197112120">(May 11 2020 at 08:00)</a>:</h4>
<p>Also worth noting, <code>target_feature_11</code> (allow safe calls if the required target_features are enabled in the caller) as implemented in <a href="https://github.com/rust-lang/rust/issues/69274">#69274</a> does not consider any such implications, it just checks if the set of <code>target_feature(enable="foo")</code> attributes on one function are a superset of the attributes on the other function.</p>



<a name="197112412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Excessive%20CPU%20Feature%20Requirements%20in%20the%20docs%3F/near/197112412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Excessive.20CPU.20Feature.20Requirements.20in.20the.20docs.3F.html#197112412">(May 11 2020 at 08:03)</a>:</h4>
<p>(To be clear, that's is not just an arbitrary choice in the implementation PR, it matches the RFC text, but you could argue that this part of the RFC should be re-considered too.)</p>



<a name="197180809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Excessive%20CPU%20Feature%20Requirements%20in%20the%20docs%3F/near/197180809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Excessive.20CPU.20Feature.20Requirements.20in.20the.20docs.3F.html#197180809">(May 11 2020 at 17:47)</a>:</h4>
<p>Hmm, even if Rust wasn't making a decision about target feature relationships:</p>
<ul>
<li>either those functions don't need <code>sse</code> in the requirements, because the data types used for inputs and outputs are there even without <code>sse</code>, after all.</li>
<li>or many, many other functions are actually wrong and they should also be declaring "foo" + "bar" for a bunch of situations, and they need to have their requirements updated accordingly.</li>
</ul>
<p>I guess we need to handle the hierarchy eventually, but for now i will proceed under the assumption that the docs are simply wrong for that small set of functions and that <code>avx</code> is the only true requirement.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>